package com.suse.common.util.date;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * <p>
 * 日期时间格式化类
 * </p>
 *
 * @author 辜玉彬
 * @since 2022-09-06 19:55
 */
public class DateFormatter {

    private final DateTimeFormatter formatter;

    public DateFormatter(DateTimeFormatter formatter) {
        this.formatter = formatter;
    }

    public static DateFormatter ofPattern(String pattern) {
        return new DateFormatter(DateTimeFormatter.ofPattern(pattern));
    }

    public String format(Date date) {
        LocalDateTime localDateTime = DateUtil.localDateTime(date);
        return formatter.format(localDateTime);
    }

}
